<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>

    <div id="app">
        <Shopcar :items="items"></Shopcar>
    </div>

    <template id="com">
        <div>
           <p v-for="(item,index) of items" :key="index">{{item.name}} --- {{item.price}}</p>
           <p>总价是 == {{total}}</p>
        </div>
       
    </template> 

    <script src="../../vue.js"></script>
    <script>    
        var shopcar = {
            template : '#com',
            props : ['items'],
            computed : {
                total(){
                    let totalPrice = 0;
                    for(let item of this.items){
                        totalPrice += item.price    
                    }
                    return totalPrice
                }
            }
        }

        new Vue({
            el :　'#app',
            data : {
                items : [
                    {name : '三国演义',price : 111},
                    {name : '水浒',price : 222},
                    {name : '红楼',price : 333}
                ]
            },
            components : {
                'Shopcar' : shopcar // wenzhang,这是ES6的对象简写方式
            }
        })
    </script>
</body>
</html>